﻿Imports System.Data.OleDb

Public Class LoaiMonDAO

    Public Function GetTable() As DataTable
        Dim dt As DataTable = New DataTable()
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = "select * from LOAIMON"
        Dim da As OleDbDataAdapter = New OleDbDataAdapter(str, cn)
        da.Fill(dt)

        cn.Close()
        Return dt
    End Function

    Public Function Insert(ByVal tmp As LoaiMonDTO) As Integer
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = "insert into LOAIMON (TenLoai) values (@TenLoai)"
        Dim cmd As OleDbCommand = New OleDbCommand(str, cn)

        Dim para1 As OleDbParameter
        para1 = New OleDbParameter("@TenLoai", tmp.TenLoai)
        cmd.Parameters.Add(para1)

        Dim result As Integer = cmd.ExecuteNonQuery()
        cn.Close()
        Return result
    End Function

    Public Function Update(ByVal tmp As LoaiMonDTO) As Integer
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = "update LOAIMON set TenLoai=@TenLoai where MaLoai=@MaLoai"
        Dim cmd As OleDbCommand = New OleDbCommand(str, cn)

        Dim para1, para2 As OleDbParameter
        para1 = New OleDbParameter("@TenLoai", tmp.TenLoai)
        cmd.Parameters.Add(para1)
        para2 = New OleDbParameter("@MaLoai", tmp.MaLoai)
        cmd.Parameters.Add(para2)

        Dim result As Integer = cmd.ExecuteNonQuery()
        cn.Close()
        Return result
    End Function

    Public Function Delete(ByVal tmp As LoaiMonDTO) As Integer
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = "delete from LOAIMON where MaLoai=@MaLoai"
        Dim cmd As OleDbCommand = New OleDbCommand(str, cn)

        Dim para1 As OleDbParameter
        para1 = New OleDbParameter("@MaLoai", tmp.MaLoai)
        cmd.Parameters.Add(para1)

        Dim result As Integer = cmd.ExecuteNonQuery()
        cn.Close()
        Return result
    End Function

End Class
